

<!DOCTYPE html>
<html lang="zh-CN" data-default-color-scheme=&#34;auto&#34;>



<head>
  <meta charset="UTF-8">
  <link rel="apple-touch-icon" sizes="76x76" href="/img/2.jpg">
  <link rel="icon" type="image/png" href="/img/2.jpg">
  <meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no">
  <meta http-equiv="x-ua-compatible" content="ie=edge">
  
  <meta name="theme-color" content="#2f4154">
  <meta name="description" content="">
  <meta name="author" content="K">
  <meta name="keywords" content="">
  <title>docker-监控 - K</title>

  <link  rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/css/bootstrap.min.css" />


  <link  rel="stylesheet" href="https://cdn.staticfile.org/github-markdown-css/4.0.0/github-markdown.min.css" />
  <link  rel="stylesheet" href="/lib/hint/hint.min.css" />

  
    
    
      
      <link  rel="stylesheet" href="https://cdn.staticfile.org/highlight.js/10.0.0/styles/github-gist.min.css" />
    
  

  


<!-- 主题依赖的图标库，不要自行修改 -->

<link rel="stylesheet" href="//at.alicdn.com/t/font_1749284_ba1fz6golrf.css">



<link rel="stylesheet" href="//at.alicdn.com/t/font_1736178_kmeydafke9r.css">


<link  rel="stylesheet" href="/css/main.css" />

<!-- 自定义样式保持在最底部 -->


  <script  src="/js/utils.js" ></script>
  <script  src="/js/color-schema.js" ></script>
<meta name="generator" content="Hexo 5.2.0"></head>


<body>
  <header style="height: 70vh;">
    <nav id="navbar" class="navbar fixed-top  navbar-expand-lg navbar-dark scrolling-navbar">
  <div class="container">
    <a class="navbar-brand"
       href="/">&nbsp;<strong>かい</strong>&nbsp;</a>

    <button id="navbar-toggler-btn" class="navbar-toggler" type="button" data-toggle="collapse"
            data-target="#navbarSupportedContent"
            aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
      <div class="animated-icon"><span></span><span></span><span></span></div>
    </button>

    <!-- Collapsible content -->
    <div class="collapse navbar-collapse" id="navbarSupportedContent">
      <ul class="navbar-nav ml-auto text-center">
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/">
                <i class="iconfont icon-home-fill"></i>
                首页
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/archives/">
                <i class="iconfont icon-archive-fill"></i>
                归档
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/categories/">
                <i class="iconfont icon-category-fill"></i>
                分类
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/tags/">
                <i class="iconfont icon-tags-fill"></i>
                标签
              </a>
            </li>
          
        
          
          
          
          
            <li class="nav-item">
              <a class="nav-link" href="/about/">
                <i class="iconfont icon-user-fill"></i>
                关于
              </a>
            </li>
          
        
        
          <li class="nav-item" id="search-btn">
            <a class="nav-link" data-toggle="modal" data-target="#modalSearch">&nbsp;<i
                class="iconfont icon-search"></i>&nbsp;</a>
          </li>
        
        
          <li class="nav-item" id="color-toggle-btn">
            <a class="nav-link" href="javascript:">&nbsp;<i
                class="iconfont icon-dark" id="color-toggle-icon"></i>&nbsp;</a>
          </li>
        
      </ul>
    </div>
  </div>
</nav>

    <div class="banner intro-2" id="background" parallax=true
         style="background: url('/img/1.jpg') no-repeat center center;
           background-size: cover;">
      <div class="full-bg-img">
        <div class="mask flex-center" style="background-color: rgba(0, 0, 0, 0.3)">
          <div class="container page-header text-center fade-in-up">
            <span class="h2" id="subtitle">
              
            </span>

            
              <div class="mt-3">
  
  
    <span class="post-meta">
      <i class="iconfont icon-date-fill" aria-hidden="true"></i>
      <time datetime="2020-12-15 14:00" pubdate>
        2020年12月15日 下午
      </time>
    </span>
  
</div>

<div class="mt-1">
  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-chart"></i>
      2k 字
    </span>
  

  
    
    <span class="post-meta mr-2">
      <i class="iconfont icon-clock-fill"></i>
      
      
      28
       分钟
    </span>
  

  
  
</div>

            
          </div>

          
        </div>
      </div>
    </div>
  </header>

  <main>
    
      

<div class="container-fluid">
  <div class="row">
    <div class="d-none d-lg-block col-lg-2"></div>
    <div class="col-lg-8 nopadding-md">
      <div class="container nopadding-md" id="board-ctn">
        <div class="py-5" id="board">
          <article class="post-content mx-auto" id="post">
            <!-- SEO header -->
            <h1 style="display: none">docker-监控</h1>
            
            <div class="markdown-body" id="post-body">
              <h2 id="监控"><a href="#监控" class="headerlink" title="监控"></a>监控</h2><ul>
<li>sysdig cadvisor promethus，这些都是第三方监控软件</li>
<li>原生监控<blockquote>
<p>docker ps </p>
</blockquote>
<pre><code class="hljs livecodeserver"> <span class="hljs-comment"># 查看docker web1的信息</span>
 [root@localhost ~]<span class="hljs-comment"># docker ps</span>
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS               NAMES
d1d4556a96ad        httpd               <span class="hljs-string">&quot;httpd-foreground&quot;</span>   <span class="hljs-number">30</span> <span class="hljs-built_in">seconds</span> ago      Up <span class="hljs-number">28</span> <span class="hljs-built_in">seconds</span>       <span class="hljs-number">80</span>/tcp              web1

</code></pre>
<blockquote>
<p>docker top 容器名</p>
</blockquote>
<pre><code class="hljs angelscript"> # 查看docker web1 的进程等
<span class="hljs-string">[root@localhost ~]</span># docker top web1
UID                 PID                 PPID                C                   STIME               TTY                 TIME                CMD
root                <span class="hljs-number">3623</span>                <span class="hljs-number">3605</span>                <span class="hljs-number">0</span>                   <span class="hljs-number">21</span>:<span class="hljs-number">58</span>               pts/<span class="hljs-number">0</span>               <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>            httpd -DFOREGROUND
bin                 <span class="hljs-number">3666</span>                <span class="hljs-number">3623</span>                <span class="hljs-number">0</span>                   <span class="hljs-number">21</span>:<span class="hljs-number">58</span>               pts/<span class="hljs-number">0</span>               <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>            httpd -DFOREGROUND
bin                 <span class="hljs-number">3667</span>                <span class="hljs-number">3623</span>                <span class="hljs-number">0</span>                   <span class="hljs-number">21</span>:<span class="hljs-number">58</span>               pts/<span class="hljs-number">0</span>               <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>            httpd -DFOREGROUND
bin                 <span class="hljs-number">3668</span>                <span class="hljs-number">3623</span>                <span class="hljs-number">0</span>                   <span class="hljs-number">21</span>:<span class="hljs-number">58</span>               pts/<span class="hljs-number">0</span>               <span class="hljs-number">00</span>:<span class="hljs-number">00</span>:<span class="hljs-number">00</span>            httpd -DFOREGROUND</code></pre>
<blockquote>
<p>docker stats 或 docker stats 容器名</p>
</blockquote>
<pre><code class="hljs angelscript"> # 查看容器的cpu 内存等占用率
<span class="hljs-string"> [root@localhost ~]</span># docker stats
 CONTAINER ID        NAME                CPU %               MEM USAGE / LIMIT     MEM %               NET I/O             BLOCK I/O           PIDS
d1d4556a96ad        web1                <span class="hljs-number">0.00</span>%               <span class="hljs-number">12.34</span>MiB / <span class="hljs-number">972.4</span>MiB   <span class="hljs-number">1.27</span>%               <span class="hljs-number">2.42</span>kB / <span class="hljs-number">0</span>B         <span class="hljs-number">17.2</span>MB / <span class="hljs-number">0</span>B         <span class="hljs-number">82</span>
</code></pre>
<h2 id="prometheus的优点"><a href="#prometheus的优点" class="headerlink" title="prometheus的优点"></a>prometheus的优点</h2></li>
<li>非常少的外部依赖，安装使用超简单</li>
<li>已经有非常多的系统集成(docker haproxy nginx jmx等)</li>
<li>服务自动化发现</li>
<li>直接集成到代码</li>
<li>设计思路按照分布式，微服务框架来实现</li>
</ul>
<h2 id="prometheus的特性"><a href="#prometheus的特性" class="headerlink" title="prometheus的特性"></a>prometheus的特性</h2><ul>
<li>自定义多维度的数据模型</li>
<li>非常高效的储存 (采集一个数据约占 3.5bytes左右 )</li>
<li>强大的查询语句</li>
<li>轻松实现数据可视化</li>
</ul>
<h2 id="数据模型指标"><a href="#数据模型指标" class="headerlink" title="数据模型指标"></a>数据模型指标</h2><ol>
<li><p>定义全局指标，添加不同维度的数据，且可以临时添加，满足不同的业务需求。<br>传统模型记录占用资源情况，只能拥有单个模型，如：根据容器的镜像、名称、环境等统计对内存的使用情况，只能每张统计表记录一个维度，数据量和数据存储量增加。</p>
</li>
<li><p>而prometheus 则可以将所有的维度集中到一块，根据不同的需求进行记录。</p>
</li>
<li><p>prometheus中的promsql，一种灵活的查询语言，可以利用多为欸都数据完成复杂的查询，如根据容器镜像计算容器内存的使用情况等，发挥数据的价值。</p>
</li>
</ol>
<h2 id="prometheus采集原理-框架结构"><a href="#prometheus采集原理-框架结构" class="headerlink" title="prometheus采集原理(框架结构)"></a>prometheus采集原理(框架结构)</h2><p> <img src="/images/docker/prometheus.png" srcset="/img/loading.gif"></p>
<ul>
<li><p>Prometheus Server</p>
<blockquote>
<p>负责运行 node-exporter 拉取和存储监控数据，并提供一套灵活的查询语言，(promQL)供用户使用</p>
</blockquote>
</li>
<li><p>node-exporter </p>
<blockquote>
<p>exporter负责收集目标对象(host,container)的性能数据，通过http接口供prometheus server获取</p>
</blockquote>
</li>
<li><p>WebUI/Grafana/API clients</p>
<blockquote>
<p>是一套可视化组件<br>监控数据的可视化展示对于监控方案至关重要。之前prometheus自己开发了一套工具，不过后来废弃了，因为开源社区出现了更优秀的产品：Grafana。Grafana能够与Prometheus无缝集成，提供完美的数据展示功能。</p>
</blockquote>
</li>
<li><p>Alertmanager</p>
<blockquote>
<p>用户可以定义基于数据监控的警告规则，规则会触发警告，会通过预定义的方式发出警告，支持的方式有 email pagerduty，webhook等</p>
</blockquote>
</li>
<li><p>node-exporter采集到数据时会交给 Prometheus Server ，然后它会将数据做成可视化数据，供查看，如果硬件信息有异常会通过 Alertmanager 报警</p>
</li>
</ul>
<h2 id="Prometheus监控"><a href="#Prometheus监控" class="headerlink" title="Prometheus监控"></a>Prometheus监控</h2><ul>
<li><p>Prometheus需要多种第三方工具来收集数据，如接下来要使用的<code>cAdvisor</code>和<code>node-exporter</code>，最终Prometheus使用<code>Grafana</code>进行监控数据的展示</p>
<table>
<thead>
<tr>
<th>192.168.100.211</th>
<th>cadvisor node-exporter</th>
</tr>
</thead>
<tbody><tr>
<td>192.168.100.212</td>
<td>prometheus cadvisor node-exporter grfana</td>
</tr>
</tbody></table>
<h2 id="cadvisor-监控"><a href="#cadvisor-监控" class="headerlink" title="cadvisor 监控"></a>cadvisor 监控</h2></li>
<li><p>cadvisor：定位为监控数据收集器</p>
</li>
<li><p>可以显示当前host中的资源使用情况，包括CPU、内存、网络、文件系统等</p>
</li>
<li><p>功能</p>
<blockquote>
<p>能够展示host和容器两个层次的监控数据<br>能够展示历史变化数据，以折线图的形式<br>可以将监控数据导出给第三方工具，由工具进一步的加工处理</p>
</blockquote>
<hr>
<blockquote>
<p>下载镜像</p>
</blockquote>
<pre><code class="hljs routeros">[root@localhost ~]# docker pull google/cadvisor
Using<span class="hljs-built_in"> default </span>tag: latest
latest: Pulling <span class="hljs-keyword">from</span> google/cadvisor
ff3a5c916c92: Pull complete 
44a45bb65cdf: Pull complete 
0bbe1a2fe2a6: Pull complete 
Digest: sha256:815386ebbe9a3490f38785ab11bda34ec8dacf4634af77b8912832d4f85dca04
Status: Downloaded newer image <span class="hljs-keyword">for</span> google/cadvisor:latest
docker.io/google/cadvisor:latest</code></pre>
<blockquote>
<p>启动容器</p>
</blockquote>
<pre><code class="hljs gradle"> [root@localhost ~]# docker run --volume <span class="hljs-regexp">/:/</span>rootfs:ro --volume <span class="hljs-regexp">/var/</span>run:<span class="hljs-regexp">/var/</span>run:rw --volume <span class="hljs-regexp">/sys:/</span>sys:ro --volume <span class="hljs-regexp">/var/</span>lib<span class="hljs-regexp">/docker:/</span>var<span class="hljs-regexp">/lib/</span>docker:ro --volume <span class="hljs-regexp">/sys/</span>fs<span class="hljs-regexp">/cgroup/</span>:<span class="hljs-regexp">/sys/</span>fs<span class="hljs-regexp">/cgroup:ro -p 8080:8080 --detach=true --name cadvisor --network host google/</span>cadvisor
<span class="hljs-number">2</span>ce70349704147b3d637edcec0b27aaaaabf294c03b62c1e61283bf2a1738399

# 将本地主机的目录映射到容器内，容器监控这些目录
# --publish=-p：端口映射
# --detach=<span class="hljs-keyword">true</span> 和 -d 一样 后台运行
# --network host 设置网络类型为 host仅主机模式 可以和 prometheus通信</code></pre>
<blockquote>
<p>访问cadvisor</p>
</blockquote>
<p><code> 192.168.100.211:8080</code></p>
</li>
</ul>
<p><img src="/images/docker/cadvisor.png" srcset="/img/loading.gif"></p>
<blockquote>
<p>查看是否获取到数据</p>
</blockquote>
<p> <code> 192.168.100.211:8080/metrics</code></p>
<p><img src="/images/docker/cadvisor1.png" srcset="/img/loading.gif"></p>
<h2 id="node-exporter"><a href="#node-exporter" class="headerlink" title="node-exporter"></a>node-exporter</h2><ul>
<li>node-exporter 可以采集主机的硬件使用数据</li>
<li>这样就可以使用cAdvisor和node-exporter将容器与主机的数据都进行了收集 </li>
<li>node-exporter 收集主机的硬件使用情况 cadvisor 收集容器的硬件使用情况</li>
</ul>
<hr>
<blockquote>
<p>下载镜像</p>
</blockquote>
 <pre><code class="hljs crmsh">[root@localhost ~]<span class="hljs-comment"># docker pull prom/node-exporter</span>
Using default <span class="hljs-keyword">tag</span>: latest
latest: Pulling from prom/<span class="hljs-keyword">node</span><span class="hljs-title">-exporter</span>
<span class="hljs-number">86</span>fa074c6765: Pull complete 
ed1cd1c6cd7a: Pull complete 
ff1bb132ce7b: Pull complete 
Digest: sha256:cf66a6bbd573fd819ea09c72e21b528e9252d58d01ae13564a29749de1e48e0f
Status: Downloaded newer image for prom/<span class="hljs-keyword">node</span>-exporter:<span class="hljs-title">latest</span>
docker.io/prom/<span class="hljs-keyword">node</span>-exporter:<span class="hljs-title">latest</span>
</code></pre>
<blockquote>
<p>启动容器</p>
</blockquote>
 <pre><code class="hljs routeros">[root@localhost ~]# docker <span class="hljs-builtin-name">run</span> -d -p 9100:9100 --volume /proc:/host/proc --volume /sys:/host/sys --volume /:/rootfs --network host prom/node-exporter --path.procfs /host/proc --path.sysfs /host/sys --collector.filesystem.ignored-mount-points <span class="hljs-string">&quot;^/(sys|proc|host|etc|rootfs/var/lib/docker/containers|rootfs/var/lib/docker/overlay2|rootfs/run/docker/netns|rootfs/var/lib/docker/devicemapper|rootfs/var/lib/docker/aufs)($$|/)&quot;</span>
WARNING: Published ports are discarded when using host<span class="hljs-built_in"> network </span>mode
f3684b4506d1a558f4ce791d13bc3e389f6c6c387a12d103831b3dadb6bac7d8

<span class="hljs-comment"># 将要监控的目录映射到容器中监控，同时排除不需要监控的目录</span>
<span class="hljs-comment"># --collector.filesystem.ignored-mount-points 不需要监控的目录</span>
<span class="hljs-comment"># Network使用host，仅主机模式，prometheus直接通过node exporters进行通讯</span></code></pre>
<blockquote>
<p>访问网页（是否获取数据）</p>
</blockquote>
<p> <code>192.168.100.211:9100/metrics</code><br><img src="/images/docker/node-.png" srcset="/img/loading.gif"></p>
<ul>
<li><p>192.168.100.212主机采取同样的操作<br><img src="/images/docker/host29100.png" srcset="/img/loading.gif"><br><img src="/images/docker/host28080.png" srcset="/img/loading.gif"></p>
<h2 id="prometheus主程序"><a href="#prometheus主程序" class="headerlink" title="prometheus主程序"></a>prometheus主程序</h2><blockquote>
<p>下载</p>
</blockquote>
<pre><code class="hljs vim">[root@localhost ~]# docker pull prom/prometheus
Using default <span class="hljs-keyword">ta</span><span class="hljs-variable">g:</span> latest
lates<span class="hljs-variable">t:</span> Pulling from prom/prometheus
<span class="hljs-number">76</span>df9210b28c: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">559</span>be8e06c14: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">0</span>f8c479799f2: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">18</span>b600182fb7: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">7107</span>ca4b8b6<span class="hljs-variable">a:</span> Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">6</span>d4f7a6bf1de: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">70791</span>e712bf8: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">11</span>ccf794006c: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">44</span>dc96c0af43: Pull <span class="hljs-built_in">complete</span> 
ecdf06ab4b8d: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">50</span>e51d4c12a<span class="hljs-variable">a:</span> Pull <span class="hljs-built_in">complete</span> 
c37593abaed6: Pull <span class="hljs-built_in">complete</span> 
Diges<span class="hljs-variable">t:</span> <span class="hljs-built_in">sha256</span>:<span class="hljs-number">0</span>eac377a90d361be9da35b469def699bcd5bb26eab8a6e9068516a9910717d58
Statu<span class="hljs-variable">s:</span> Downloaded newer image <span class="hljs-keyword">for</span> prom/prometheu<span class="hljs-variable">s:latest</span>
docker.io/prom/prometheu<span class="hljs-variable">s:latest</span></code></pre>
<blockquote>
<p>添加prometheus的yml文件等启动容器时映射到容器，让prometheus获取到 node-exporter 和 cadvisor监控到的数据</p>
</blockquote>
<pre><code class="hljs routeros"> [root@localhost ~]# vi prometheus.yml

 # my global config
    global:
      scrape_interval:     15s # <span class="hljs-builtin-name">Set</span> the scrape interval <span class="hljs-keyword">to</span> every 15 seconds.<span class="hljs-built_in"> Default </span>is every 1 minute.
      evaluation_interval: 15s # Evaluate rules every 15 seconds. The<span class="hljs-built_in"> default </span>is every 1 minute.
      # scrape_timeout is <span class="hljs-builtin-name">set</span> <span class="hljs-keyword">to</span> the global<span class="hljs-built_in"> default </span>(10s).

    # Alertmanager configuration
    alerting:
      alertmanagers:
      - static_configs:
        - targets:
          # - alertmanager:9093

    # Load rules once <span class="hljs-keyword">and</span> periodically evaluate them according <span class="hljs-keyword">to</span> the global <span class="hljs-string">&#x27;evaluation_interval&#x27;</span>.
    rule_files:
      # - <span class="hljs-string">&quot;first_rules.yml&quot;</span>
      # - <span class="hljs-string">&quot;second_rules.yml&quot;</span>

    # A scrape configuration containing exactly one endpoint <span class="hljs-keyword">to</span> scrape:
    # Here it<span class="hljs-string">&#x27;s Prometheus itself.</span>
<span class="hljs-string">    scrape_configs:</span>
<span class="hljs-string">      # The job name is added as a label `job=&lt;job_name&gt;` to any timeseries scraped from this config.</span>
<span class="hljs-string">      - job_name: &#x27;</span>prometheus<span class="hljs-string">&#x27;</span>
<span class="hljs-string"></span>
<span class="hljs-string">        # metrics_path defaults to &#x27;</span>/metrics<span class="hljs-string">&#x27;</span>
<span class="hljs-string">        # scheme defaults to &#x27;</span>http<span class="hljs-string">&#x27;.</span>
<span class="hljs-string"></span>
<span class="hljs-string">        static_configs:</span>
<span class="hljs-string">        - targets: [&#x27;</span>localhost:9090<span class="hljs-string">&#x27;,&#x27;</span>localhost:8080<span class="hljs-string">&#x27;,&#x27;</span>localhost:9100<span class="hljs-string">&#x27;,&#x27;</span>192.168.100.211:8080<span class="hljs-string">&#x27;,&#x27;</span>192.168.100.211:9100<span class="hljs-string">&#x27;]</span>
<span class="hljs-string"></span>
<span class="hljs-string"># Targets：exporter要抓取的数据，要指定两台主机的exporter和cadvisor，9090为prometheus自己</span>
<span class="hljs-string"># 这里prometheus抓取了 本地的9090端口(prometheus主程序) 8080端口(cadvisor) 9100端口(node-exporter) 的数据</span>
<span class="hljs-string"># 和 192.168.100.212的 8080端口(cadvisor) 9100端口(node-exporter) 的数据</span>
<span class="hljs-string"></span>
<span class="hljs-string"># 该配置文件可以从prometheus官网获取  https://prometheus.io/docs/prometheus/latest/getting_started/</span></code></pre>
<blockquote>
<p>启动容器</p>
</blockquote>
<pre><code class="hljs routeros">[root@localhost ~]# docker <span class="hljs-builtin-name">run</span> -d -p 9090:9090 --volume /root/prometheus.yml:/etc/prometheus/prometheus.yml --name prometheus --network host prom/prometheus
WARNING: Published ports are discarded when using host<span class="hljs-built_in"> network </span>mode
1db6334366c4353a58ba526eea42467e22c95ac60e344e11628e25785a96c1e2
 # 将刚刚写的文件映射到容器内
 # 网卡类型为 host 仅主机模式
</code></pre>
<blockquote>
<p>访问9090端口页面<br><code>http://192.168.100.212:9090/targets</code></p>
</blockquote>
<ul>
<li>所有主机都是 up 状态就没问题了<br><img src="/images/docker/pro9090.png" srcset="/img/loading.gif"> <h2 id="grafana可视化ui"><a href="#grafana可视化ui" class="headerlink" title="grafana可视化ui"></a>grafana可视化ui</h2></li>
<li>讲数据传给 grafana显示数据<blockquote>
<p>下载镜像</p>
</blockquote>
<pre><code class="hljs vim">[root@localhost ~]# docker pull grafana/grafana
Using default <span class="hljs-keyword">ta</span><span class="hljs-variable">g:</span> latest
lates<span class="hljs-variable">t:</span> Pulling from grafana/grafana
<span class="hljs-number">188</span>c0c94c7c5: Pull <span class="hljs-built_in">complete</span> 
cf416974017c: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">906611</span>c1c3a0: Pull <span class="hljs-built_in">complete</span> 
b0a33b67ee73: Pull <span class="hljs-built_in">complete</span> 
f22dcf836126: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">4</span>f4fb700ef54: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">970060</span>b65362: Pull <span class="hljs-built_in">complete</span> 
<span class="hljs-number">95</span>e5bfa5fa14: Pull <span class="hljs-built_in">complete</span> 
Diges<span class="hljs-variable">t:</span> <span class="hljs-built_in">sha256</span>:<span class="hljs-number">511</span>bc20bfcd1b79f3947bb1c33d152f7484e7a91418883fb4dddf71274227321
Statu<span class="hljs-variable">s:</span> Downloaded newer image <span class="hljs-keyword">for</span> grafana/grafan<span class="hljs-variable">a:latest</span>
docker.io/grafana/grafan<span class="hljs-variable">a:latest</span>
</code></pre>
<blockquote>
<p>启动容器</p>
</blockquote>
<pre><code class="hljs asciidoc">[root@localhost ~]# docker run -d -i -p 3000:3000 -e &quot;GF<span class="hljs-emphasis">_SERVER_</span>ROOT<span class="hljs-emphasis">_URL&quot;=http://grafana.server.name -e &quot;GF_</span>SECURITY<span class="hljs-emphasis">_ADMIN_</span>PASSWORD=security&quot; --network host grafana/grafana
<span class="hljs-symbol">WARNING: </span>Published ports are discarded when using host network mode
e3668f9647973848764159f0c6eddd6f581b8fb578680c03ae6a09b339624264

# GF<span class="hljs-emphasis">_SERVER_</span>ROOT<span class="hljs-emphasis">_URL&quot;=http://grafana.server.name 这个是grfana的默认用户名 admin </span>
<span class="hljs-emphasis"># &quot;GF_</span>SECURITY<span class="hljs-emphasis">_ADMIN_</span>PASSWORD=security&quot; 这个是指定用户名密码 security</code></pre>
<blockquote>
<p>访问页面</p>
</blockquote>
</li>
</ul>
<p><img src="/images/docker/gfn01.png" srcset="/img/loading.gif"> </p>
<blockquote>
<p>将prometheus添加</p>
</blockquote>
<p><img src="/images/docker/gfn02.png" srcset="/img/loading.gif"><br><img src="/images/docker/gfn03.png" srcset="/img/loading.gif"><br><img src="/images/docker/gfn04.png" srcset="/img/loading.gif"> </p>
<blockquote>
<p>添加仪表盘</p>
</blockquote>
<p><img src="/images/docker/gfn05.png" srcset="/img/loading.gif"><br>可以在官网找合适的 （<a target="_blank" rel="noopener" href="https://grafana.com/grafana/dashboards%EF%BC%89">https://grafana.com/grafana/dashboards）</a><br><img src="/images/docker/gfn06.png" srcset="/img/loading.gif"><br><img src="/images/docker/gfn07.png" srcset="/img/loading.gif"> </p>
<ul>
<li>监控完成<br><img src="/images/docker/gfn08.png" srcset="/img/loading.gif"> </li>
</ul>
</li>
</ul>

            </div>
            <hr>
            <div>
              <div class="post-metas mb-3">
                
                  <div class="post-meta mr-3">
                    <i class="iconfont icon-category"></i>
                    
                      <a class="hover-with-bg" href="/categories/docker/">docker</a>
                    
                  </div>
                
                
                  <div class="post-meta">
                    <i class="iconfont icon-tags"></i>
                    
                      <a class="hover-with-bg" href="/tags/docker/">docker</a>
                    
                  </div>
                
              </div>
              
                <p class="note note-warning">本博客所有文章是以学习为目的，如果有不对的地方可以一起交流沟通共同学习 邮箱:1248287831@qq.com！</p>
              
              
                <div class="post-prevnext row">
                  <article class="post-prev col-6">
                    
                    
                      <a href="/2020/12/15/docker-%E6%97%A5%E5%BF%97%E7%AE%A1%E7%90%86/">
                        <i class="iconfont icon-arrowleft"></i>
                        <span class="hidden-mobile">docker-日志管理</span>
                        <span class="visible-mobile">上一篇</span>
                      </a>
                    
                  </article>
                  <article class="post-next col-6">
                    
                    
                      <a href="/2020/12/14/docker-weave/">
                        <span class="hidden-mobile">docker-weave网络</span>
                        <span class="visible-mobile">下一篇</span>
                        <i class="iconfont icon-arrowright"></i>
                      </a>
                    
                  </article>
                </div>
              
            </div>

            
          </article>
        </div>
      </div>
    </div>
    
      <div class="d-none d-lg-block col-lg-2 toc-container" id="toc-ctn">
        <div id="toc">
  <p class="toc-header"><i class="iconfont icon-list"></i>&nbsp;目录</p>
  <div id="tocbot"></div>
</div>

      </div>
    
  </div>
</div>

<!-- Custom -->


    
  </main>

  
    <a id="scroll-top-button" href="#" role="button">
      <i class="iconfont icon-arrowup" aria-hidden="true"></i>
    </a>
  

  
    <div class="modal fade" id="modalSearch" tabindex="-1" role="dialog" aria-labelledby="ModalLabel"
     aria-hidden="true">
  <div class="modal-dialog modal-dialog-scrollable modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <h4 class="modal-title w-100 font-weight-bold">搜索</h4>
        <button type="button" id="local-search-close" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body mx-3">
        <div class="md-form mb-5">
          <input type="text" id="local-search-input" class="form-control validate">
          <label data-error="x" data-success="v"
                 for="local-search-input">关键词</label>
        </div>
        <div class="list-group" id="local-search-result"></div>
      </div>
    </div>
  </div>
</div>
  

  

  <footer class="text-center mt-5 py-3">
  <div class="footer-content">
     <a href="https://space.bilibili.com/39165374" target="_blank" rel="nofollow noopener"><span>LMK</span></a> <i class="iconfont icon-love"></i> <a href="https://github.com/fluid-dev/hexo-theme-fluid" target="_blank" rel="nofollow noopener"><span>Fluid</span></a> 
  </div>
  
  <div class="statistics">
    
    

    
      
        <!-- 不蒜子统计PV -->
        <span id="busuanzi_container_site_pv" style="display: none">
            总访问量 
            <span id="busuanzi_value_site_pv"></span>
             次
          </span>
      
      
        <!-- 不蒜子统计UV -->
        <span id="busuanzi_container_site_uv" style="display: none">
            总访客数 
            <span id="busuanzi_value_site_uv"></span>
             人
          </span>
      
    
  </div>


  

  
</footer>

<!-- SCRIPTS -->
<script  src="https://cdn.staticfile.org/jquery/3.4.1/jquery.min.js" ></script>
<script  src="https://cdn.staticfile.org/twitter-bootstrap/4.4.1/js/bootstrap.min.js" ></script>
<script  src="/js/debouncer.js" ></script>
<script  src="/js/main.js" ></script>

<!-- Plugins -->


  
    <script  src="/js/lazyload.js" ></script>
  



  



  <script defer src="https://cdn.staticfile.org/clipboard.js/2.0.6/clipboard.min.js" ></script>
  <script  src="/js/clipboard-use.js" ></script>



  <script defer src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js" ></script>





  <script  src="https://cdn.staticfile.org/tocbot/4.11.1/tocbot.min.js" ></script>
  <script>
    $(document).ready(function () {
      var boardCtn = $('#board-ctn');
      var boardTop = boardCtn.offset().top;

      tocbot.init({
        tocSelector: '#tocbot',
        contentSelector: '#post-body',
        headingSelector: 'h1,h2,h3,h4,h5,h6',
        linkClass: 'tocbot-link',
        activeLinkClass: 'tocbot-active-link',
        listClass: 'tocbot-list',
        isCollapsedClass: 'tocbot-is-collapsed',
        collapsibleClass: 'tocbot-is-collapsible',
        collapseDepth: 0,
        scrollSmooth: true,
        headingsOffset: -boardTop
      });
      if ($('.toc-list-item').length > 0) {
        $('#toc').css('visibility', 'visible');
      }
    });
  </script>



  <script  src="https://cdn.staticfile.org/typed.js/2.0.11/typed.min.js" ></script>
  <script>
    var typed = new Typed('#subtitle', {
      strings: [
        '  ',
        "docker-监控&nbsp;",
      ],
      cursorChar: "_",
      typeSpeed: 70,
      loop: false,
    });
    typed.stop();
    $(document).ready(function () {
      $(".typed-cursor").addClass("h2");
      typed.start();
    });
  </script>



  <script  src="https://cdn.staticfile.org/anchor-js/4.2.2/anchor.min.js" ></script>
  <script>
    anchors.options = {
      placement: "right",
      visible: "hover",
      
    };
    var el = "h1,h2,h3,h4,h5,h6".split(",");
    var res = [];
    for (item of el) {
      res.push(".markdown-body > " + item)
    }
    anchors.add(res.join(", "))
  </script>



  <script  src="/js/local-search.js" ></script>
  <script>
    var path = "/local-search.xml";
    var inputArea = document.querySelector("#local-search-input");
    inputArea.onclick = function () {
      searchFunc(path, 'local-search-input', 'local-search-result');
      this.onclick = null
    }
  </script>



  <script  src="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.js" ></script>
  <link  rel="stylesheet" href="https://cdn.staticfile.org/fancybox/3.5.7/jquery.fancybox.min.css" />

  <script>
    $('#post img:not(.no-zoom img, img[no-zoom]), img[zoom]').each(
      function () {
        var element = document.createElement('a');
        $(element).attr('data-fancybox', 'images');
        $(element).attr('href', $(this).attr('src'));
        $(this).wrap(element);
      }
    );
  </script>















</body>
</html>
